Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lru_map

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lru_map

Finite key-value map using the Least Recently Used (LRU) algorithm where the most recently used objects are keept in the map while less recently used items are evicted to make room for new ones.

  • 0.3.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is lru_map?

The lru_map npm package provides a simple and efficient implementation of a Least Recently Used (LRU) cache. This type of cache automatically removes the least recently used items when the cache reaches its maximum size, making it useful for managing memory in applications where cache size needs to be limited.

What are lru_map's main functionalities?

Creating an LRU Cache

This feature allows you to create an LRU cache with a specified maximum size. The cache will automatically evict the least recently used items when it reaches this size.

const LRUMap = require('lru_map').LRUMap;
const cache = new LRUMap(5); // Create an LRU cache with a maximum size of 5

Adding and Retrieving Items

You can add items to the cache using the set method and retrieve them using the get method. If the item is in the cache, it will be returned; otherwise, undefined will be returned.

cache.set('key1', 'value1');
console.log(cache.get('key1')); // Outputs: 'value1'

Checking Cache Size

This feature allows you to check the current number of items in the cache using the size property.

console.log(cache.size); // Outputs the current size of the cache

Deleting Items

You can delete items from the cache using the delete method. After deletion, attempting to retrieve the item will return undefined.

cache.delete('key1');
console.log(cache.get('key1')); // Outputs: undefined

Clearing the Cache

This feature allows you to clear all items from the cache using the clear method, resetting the cache to its initial empty state.

cache.clear();
console.log(cache.size); // Outputs: 0

Other packages similar to lru_map

Keywords

FAQs

Package last updated on 11 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc